home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tricks of the Mac Game Programming Gurus
/
TricksOfTheMacGameProgrammingGurus.iso
/
More Source
/
Libraries
/
SAT 2.3b4
/
Demo ƒ
/
HeartQuest demo ƒ
/
sFlypaper.p
< prev
next >
Wrap
Text File
|
1995-01-22
|
4KB
|
156 lines
{===============================================}
{================= Flypaper sprite unit ================}
{===============================================}
{ Example file for Ingemars Sprite Animation Toolkit. }
{ © Ingemar Ragnemalm 1992 }
{ See doc files for legal terms for using this code. }
unit sFlypaper;
{ Sprite unit. A sprite unit should include the following routines:}
{ Init-procedure, that initializes private bitmaps}
{ Setup-procedure, that sets variables other than the standard ones set by MakeSprite }
{ Handle-procedure, to be called once per iteration until the sprite dies }
{ Hittask-procedure (optional), for advanced collission handling. }
{ Flypaper object, the "enemies" in the HeartQuest game. }
interface
uses
{$IFC UNDEFINED THINK_PASCAL}
Types, Quickdraw,
{$ENDC}
SAT, scores, SoundConst, GameGlobals;
var
slowcount: integer;
procedure InitFlypaper;
procedure SetupFlypaper (mp: SpritePtr);
procedure HandleFlypaper (me: SpritePtr);
procedure HandleDyingFlypaper (me: SpritePtr); {Behöver inte vara extern}
implementation
var
FlypaperFace: array[1..6] of FacePtr;
DyingFlypaperFace: array[1..3] of FacePtr;
procedure InitFlypaper;
var
ii: integer;
h: Handle;
begin
for ii := 1 to 6 do
FlypaperFace[ii] := SATGetFace(156 + ii);
for ii := 1 to 3 do
DyingFlypaperFace[ii] := SATGetFace(143 + ii);
end;
procedure SetupFlypaper (mp: SpritePtr);
begin
mp^.face := FlypaperFace[1];
mp^.mode := SATRand(3) + 1; { icon number }
SetRect(mp^.hotRect, -14 + 16, -28 + 32, 14 + 16, 0 + 32);
mp^.task := @HandleFlypaper;
end;
procedure HandleFlypaper (me: SpritePtr);
var
mp: Spriteptr;
divmed: integer;
begin
if me^.kind <> -3 then
begin
me^.kind := -3;
if slowcount < 10 then
begin
slowcount := 50;
SATSoundPlay(Splatt2SndH, 1, true);
me^.task := @HandleDyingFlypaper;
me^.kind := 0;
end;
end;
me^.mode := me^.mode + 1;
if me^.mode = 7 then
me^.mode := 1;
me^.face := FlypaperFace[me^.mode];
me^.position.h := me^.position.h + me^.speed.h;
me^.position.v := me^.position.v + me^.speed.v;
if SATRand100 < 7 then
me^.speed.h := SATRand(15) - 8;
if SATRand100 < 4 then
me^.speed.v := SATRand(7) - 4;
if (level > 4) then
if SATRand100 < level then
if slowcount = 0 then
begin
me^.speed.h := PlayerPos.h - me^.position.h;
me^.speed.v := PlayerPos.v - me^.position.v;
divmed := abs(me^.speed.h) + abs(me^.speed.v);
if divmed > level then
begin
me^.speed.h := me^.speed.h * 2 * level div divmed;
me^.speed.v := me^.speed.v * 2 * level div divmed;
end;
end
else {Player stunned - keep away!}
begin
me^.speed.h := -(PlayerPos.h - me^.position.h);
me^.speed.v := -(PlayerPos.v - me^.position.v);
divmed := abs(me^.speed.h) + abs(me^.speed.v);
if divmed > level then
begin
me^.speed.h := me^.speed.h * 2 * level div divmed;
me^.speed.v := me^.speed.v * 2 * level div divmed;
end;
end;
if me^.position.h < 0 then
begin
me^.position.h := 0;
me^.speed.h := 1;
end;
if me^.position.h > gSAT.offSizeH - xsize then
begin
me^.position.h := gSAT.offSizeH - xsize;
me^.speed.h := -1;
end;
if me^.position.v < 0 then
begin
me^.position.v := 0;
me^.speed.v := 1;
end;
if me^.position.v > gSAT.offSizeV - 32 then
begin
me^.position.v := gSAT.offSizeV - 32;
me^.speed.v := -1;
end;
end;
procedure HandleDyingFlypaper (me: SpritePtr);
var
mp: Spriteptr;
divmed: integer;
begin
if me^.kind <> 0 then
me^.kind := 0;
me^.mode := me^.mode + 1;
if me^.mode >= 4 then
me^.mode := 1;
me^.face := DyingFlypaperFace[me^.mode];
me^.position.v := me^.position.v + 8;
if me^.position.h > gSAT.offSizeH then
me^.task := nil;
end;
end.